package mario.game.graymachine.sprite;

import mario.game.graymachine.R;
import mario.game.graymachine.core.Scene;

public class Sprite1 extends GLSprite {
	int hp = 100;
	static final int ARRAY_LENGTH=10;
	public Sprite1(Scene scene) {
		super(scene);
		type=GLSprite.TYPE_POWERUP;
		
		mResourceIds = new int[5][ARRAY_LENGTH];
		/** date|date|date|timer|number */
		mTextureNames = new int[5][ARRAY_LENGTH+2];//more 2 grid to store timeindex and image numbers
		
		// resouce id
		mTextureNames[1][ARRAY_LENGTH+1]=1;
		mResourceIds[1][0]=R.drawable.mac;
		
		mTextureNames[4][ARRAY_LENGTH+1]=4;
		mResourceIds[4][0]=R.drawable.powerup;
		mResourceIds[4][1]=R.drawable.powerup;
		mResourceIds[4][2]=R.drawable.powerup;
		mResourceIds[4][3]=R.drawable.powerup;
		
		width=64;
		height=64;
		cwidth=18;
		cheight=18;
	}

	@Override
	public void update(int timer) {
		super.update(timer);
		switch (state) {
		case STATE_MOVE:
			velocityX = -20;
			break;
		case STATE_DEAD:
			velocityX = -5;
			if (mTextureNames[state][ARRAY_LENGTH] + timer > 90) {
				isDead=true;
			}
			break;
		default:
			break;
		}
		x += timer * velocityX/100;
		y += timer * velocityY;
		AnimaUpdate(timer);
	}

	private void AnimaUpdate(int timer) {
		if (mTextureNames[state][ARRAY_LENGTH] + timer >= mTextureNames[state][ARRAY_LENGTH+1] * 40)
			mTextureNames[state][ARRAY_LENGTH]= 0;
		mTextureNames[state][ARRAY_LENGTH] += timer;
		setTextureName(mTextureNames[state][mTextureNames[state][ARRAY_LENGTH] / 40]);
	}
	
	@Override
	public boolean collisionWith(GLSprite something) {
		if(something.type==0){
			dead();
		}
		return super.collisionWith(something);
	}
	@Override
	public void setup() {
		super.setup();
		mTextureNames[STATE_DEAD][ARRAY_LENGTH]=0;
	}
	private void dead() {
		state=STATE_DEAD;
	}
}
